package io.polly.ldz.ai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.OpenAiImageModel;
import org.springframework.ai.openai.OpenAiImageOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ldz112@163.com
 * @description：851 497 1388
 * @date 2025/3/14 12:40
 * Copyright (C) 2023 All Rights Reserved
 */
@RestController
@RequestMapping("/v1")
public class AiController {


    @Autowired
    private ChatClient chatClient;

    @GetMapping("/chat")
    public String chat(@RequestParam(value= "msg",defaultValue = "给我讲个笑话") String message) {
        return chatClient.prompt()
                .user(message)
//                .system("")
                .call()
                .content();
    }

    @GetMapping(value = "/stream",produces = "text/html;charset=UTF-8")
    public String stream(){
        return null;
    }

    @Autowired
    private ChatModel chatModel;

    @GetMapping(value = "/model",produces = "text/html;charset=UTF-8")
    public String model(){

        ChatResponse chatResponse = chatModel.call(
                new Prompt("讲个笑话", OpenAiChatOptions.builder().model("gpt-4-32K").temperature(0.3).build())
        );

        return chatResponse.getResult().getOutput().getText();
    }

    @Autowired
    OpenAiImageModel openaiImageModel;
    public String text2Img(){

        ImageResponse response = openaiImageModel.call(
                new ImagePrompt("A light cream colored mini golden doodle",
                        OpenAiImageOptions.builder()
                                .quality("hd")
                                .N(1)
                                .height(1024)
                                .width(1024).build())

        );

        return response.getResult().getOutput().getUrl();
    }






}
